<?php

namespace App\Http\Controllers\home;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;

class CloudController extends Controller
{
    //
     public function index(Request $request)
    {	
    	if ($request->session()->has('homeuser')) {
            $id = $request->session()->get('homeuser')->userid;
            $username = $request->session()->get('homeuser')->username;
    		$list = DB::table('cloud')->where('userid','=',$id)->get();
            return view('home.cloud.index',['list'=>$list,'username'=>$username]);
    	}else{
            return view('home.cloud.cloudlogin');
    	}
    }
    public function store(Request $request)
    {
        // dd($request);
        // dd($request->only('a'));
        $name = $request->input("user");
        // $pass = $request->input("pwd");
        $ob = DB::table("user")->where("username",$name)->first();
        if(empty($name)){
            return back()->with("msg","请输入账号");
        }
        if($ob){
            if($request->input("pwd")==$ob->userpassword){
                session(["homeuser"=>$ob]);
                // 登陆成功进入购物车页
                return redirect("/home/cloud");
            }else{
                // return back()->with("msg","登录失败：密码错误");
            }
        }else{
            return back()->with("msg","登录失败：账号不存在");
        }
        
    }


}
